<?php
try {
    // $con =new PDO("mysql:host=mysql5.7;port=3306;dbname=mysql_test;charset=utf8","root","root");
	$con =new PDO("mysql:host=mysql5.7;port=3306;charset=utf8","root","root");
	echo "PDO扩展 连接成功 <br/>";

    // 创建测试数据库和表
    $con->exec("CREATE DATABASE IF NOT EXISTS `mysql_test` DEFAULT CHARSET utf8 COLLATE utf8_general_ci;");
    echo "PDO扩展 测试数据库创建成功 <br/>";
    $con->exec("CREATE TABLE IF NOT EXISTS `mysql_test`.`test`  (
  `id` int UNSIGNED NOT NULL AUTO_INCREMENT,
  `time` datetime NULL,
  `title` varchar(255) NULL,
  PRIMARY KEY (`id`)
);");
    echo "PDO扩展 测试数据表创建成功 <br/>";

    $con->exec("INSERT INTO `mysql_test`.`test`(`time`, `title`) VALUES ('".date('Y-m-d H:i:s')."', '测试PDO插入')");
    echo "PDO扩展 数据插入成功 <br/>";

    $stmt = $con->query('select * from `mysql_test`.`test` order by id desc limit 1');
    $rows = $stmt->fetch();
    echo "<pre>";
    var_dump($rows);
    echo "</pre>";
} catch (PDOException $e) {
	echo $e->getMessage();
}


$con = new mysqli("mysql5.7:3306","root","root");

if ($con->connect_error) {
	die("mysqli扩展 连接失败 ".$con->connect_error);
} else {
	echo "mysqli扩展 连接成功 <br/>";
}